package com.greenant.store.activity;

import com.avos.avoscloud.AVException;
import com.avos.avoscloud.SaveCallback;
import com.greenant.store.R;
import com.greenant.store.utils.Const;
import com.greenant.store.utils.UtilTools;
import com.lsarah.utils.SystemBarTintManager;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

public class OrderDescActivity extends BaseActivity {
	private Handler mHandler = new Handler(Looper.getMainLooper());
	private Context context;

	private EditText order_detail_hint;

	String comment = "";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		SystemBarTintManager.setContentView(this, R.layout.activity_order_desc, getResources().getColor(R.color.green));
		context = this;
		order_detail_hint = (EditText) this.findViewById(R.id.order_detail_hint);

		findViewById(R.id.modify).setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				if (Const.order != null) {

					Const.order.setComment(order_detail_hint.getText().toString());
					Const.order.saveInBackground(new SaveCallback() {

						@Override
						public void done(AVException arg0) {
							if (arg0 == null) {
								UtilTools.showMyToast(context, context.getString(R.string.success));
								setResult(RESULT_OK);
								finish();
							} else {
								Const.order.setComment(comment);
								UtilTools.showMyToast(context, context.getString(R.string.failed));
							}
						}
					});
				}

			}
		});
		if (Const.order != null) {
			comment = Const.order.getComment();
			if (!TextUtils.isEmpty(Const.order.getComment())) {
				order_detail_hint.setText(Const.order.getComment());
			}
		}
	}

	public void goBack(View view) {
		setResult(RESULT_CANCELED);
		finish();
	}

	public void submitFeedBack(View view) {
	}

	@Override
	public void onBackPressed() {
		setResult(RESULT_CANCELED);
		finish();
	}

	@Override
	protected void onResume() {
		super.onResume();

	}

	public void showAbout(View view) {
		Intent intent = new Intent(this, AddActivity.class);
		startActivity(intent);
	}

}
